package logic

import (
	"context"
	"rent-ease/model"

	"rent-ease/rentrpc/internal/svc"
	"rent-ease/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *rentrpc.ListRequest) (*rentrpc.ListResponse, error) {
	// todo: add your logic here and delete this line
	var rent []model.Rent
	model.DB.Find(&rent)
	var data []*rentrpc.ListRent
	for _, rents := range rent {
		listRent := rentrpc.ListRent{
			RentName: rents.RentName,
			Price:    float32(rents.Price),
			Address:  rents.Address,
		}
		data = append(data, &listRent)
	}
	return &rentrpc.ListResponse{
		List: data,
	}, nil
}
